<template>
    <div class="footer">
      <span style="color: #fff;line-height:40px;font-size: 12px;">
        Copyright © 2024 <a href="">{{Warner}}</a> All Rights Reserved.<a href="https://beian.miit.gov.cn/"> {{IPC}} </a> 
        网站已运行:  <span :style="{color: runTimeColor,fontSize:FontSize + 'px'}"> {{appRunTime}} </span>
        <!-- <a href="https://beian.miit.gov.cn/"> &nbsp 苏ICP备19067166号-1 &nbsp | &nbsp</a>  -->
      </span>
    </div>
</template>

<script>
import { listFooter } from "@/api/cms/footer";
  export default {
    name: 'cmsFooter',
    data(){
      return{
         //总运行时间
         appRunTime: "",
         //运行天数
         Day:"",
         //运行小时
         Hour:"",
         //运行分钟
         minute:"",
         //运行秒数
         second:"",
         //开始运行时间
         startRunTime:'',
         //版权归属
         Warner:'',
         //备案号
         IPC:'',
         //页脚底部网站运行时间显示颜色
         runTimeColor:'',
         //页脚底部网站运行时间字体大小
         FontSize:16,
        // timer: undefined,
        // nowTime: new Date(),
      };
    },
    
created() {
  // 显示时间
  // this.timer = setInterval(() => {
  // this.nowTime= new Date().toLocaleString();
  // });
  this.getConfigInfo();
},
mounted(){
      var that = this
      var timer = ''
      timer = window.setInterval(function logname() {
        let staytimeGap = new Date().getTime() - new Date(that.startRunTime).getTime();
        let stayDay = Math.floor(staytimeGap / (3600 * 1000 * 24));
        let leave = staytimeGap % (3600 * 1000 * 24);
        let stayHour = Math.floor(leave / (3600 * 1000));
        let leave1 = leave % (3600 * 1000);
        let stayMin = Math.floor(leave1 / (60 * 1000));
        let leave2 = leave1 % (60 * 1000);
        let staySec = Math.floor(leave2 / 1000);
        that.appRunTime = stayDay + "天" + stayHour + "时" + stayMin + "分" + staySec + "秒";
        // that.Day = stayDay + "天";
        // that.Hour = stayHour + "时";
        // that.minute = stayMin + "分";
        // that.second = staySec + "秒";
      }, 1000);
},
// 销毁定时器
// beforeDestroy() {
//   if (this.timer) {
//     clearInterval(this.timer);
//   }
// },
methods: {
  getConfigInfo(){
    listFooter().then(response=>{
      let Warner = response.rows[0].warner === ""?"寒枫博客":response.rows[0].warner;
      let IPC = response.rows[0].icp ===""?"网站备案号XXX":response.rows[0].icp;
      //添加空白占位符以及分割符
      this.IPC = "\u0020 | \u0020 " + IPC + " \u0020 |";
      this.Warner = "\u0020 " + Warner + "\u0020";
      this.runTimeColor = response.rows[0].fontColor === ""?"deeppink":response.rows[0].fontColor;
      this.FontSize = response.rows[0].fontSize === ""?"16":response.rows[0].fontSize;
      this.startRunTime = response.rows[0].startTime === ""?"2024-06-29 00:00:00":response.rows[0].startTime;
      // console.log(response.rows[0])
      
    })
    
  }
    // FormatTime() {
    //   //返回显示的日期时间格式
    //   var date = new Date();
    //   var year = this.formatTime(date.getFullYear());
    //   var month = this.formatTime(date.getMonth() + 1);
    //   var day = this.formatTime(date.getDate());
    //   var hour = this.formatTime(date.getHours());
    //   var minute = this.formatTime(date.getMinutes());
    //   var second = this.formatTime(date.getSeconds());
    //   var weekday = date.getDay();
    //   var weeks = new Array(
    //     "星期日",
    //     "星期一",
    //     "星期二",
    //     "星期三",
    //     "星期四",
    //     "星期五",
    //     "星期六"
    //   );
    //   var week = weeks[weekday];
    //   return `${year}-${month}-${day} ${hour}:${minute}:${second} ${week}`;
    // },
    // formatTime(n) {
    //   //判断是否需要加0
    //   if (n < 10) {
    //     return "0" + n;
    //   } else {
    //     return n;
    //   }
    // },
    }
  }
</script>

<style scoped>
  .footer {
    text-align: center;
  }
</style>
